import Foundation

// https://v2.jokeapi.dev/joke/Miscellaneous?lang=fr&idRange=22

func getLinkedJoke(category: String, language: String, id: String) async throws -> Joke {
    let url = "https://v2.jokeapi.dev/joke/\(category)?lang=\(language)&idRange=\(id)"
    let apiService = APIService(urlString: url)
    
    do {
        let joke: Joke = try await apiService.getJSON()
        return joke
    } catch {
        throw error
    }
}

Task {
    if let joke = try? await getLinkedJoke(category: "Any", language: "en", id: "100") {
        print(joke.joke ?? "")
        print(joke.setup ?? "")
        print(joke.delivery ?? "")
    }
}
